<template>
	<m-layout :title="title" gap="6 0 0">
		<m-block class="shop" spa="0 24 23" :isLoading='isPending' bgColor="unset">
			<!-- 列表 -->
			<view class="">
				<template v-for="item in listArr">
					<m-list :itemObj="item" />
				</template>
				<m-loading class="more pb-60" gap="100 0" :list='listArr' :pageIndex="pageIndex" :pageCount="pageCount" :loading="isLoading"  />
			</view>
		</m-block>
	</m-layout>
</template>
<script>
	import { GetNewsPage } from "@/api/News.js"
	export default {
		data() {
			return {
				isPending: true,
				pageIndex: 1,
				pageSize: 10,
				pageCount: 1,
				title: '列表',
				listArr: [],
				isLoading: false,
				typeid:'',
				code:'',
			};
		},
		props: {
		},
		onLoad({ title,typeid='',code='' }) {
			this.title = title;
			this.typeid = typeid;
			this.code=code;
		},
		mounted() {
			this.init()
		},
		methods: {
			async init() {
				this.pageCount = 1;
				this.pageIndex = 1;
				this.isPending = true;
				await this.sleep(0.5);
				await this.getData();
				this.isPending = false;
			},
			async getData() {
				if (this.pageIndex > this.pageCount) return;
				this.isLoading = true;
				const { success, totalCount, msg, list, pageCount } = await GetNewsPage({
					typeid:this.typeid,
					code:this.code,
					pageIndex: this.pageIndex,
					pageSize: this.pageSize,
				});
				this.isLoading = false;
				this.pageCount = pageCount;
				if (this.pageIndex <= 1) {
					this.listArr = list;
				} else {
					this.listArr = [...this.listArr, ...list];
				}
				this.pageIndex++;
				uni.stopPullDownRefresh();
			},
		},
		onPullDownRefresh() {
			this.init();
		},
		onReachBottom() {
			this.getData();
			console.log("触底了");
		},
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}
</style>
